package com.zcb.qingshoudan.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Xfermode;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;
import java.io.PrintStream;

public abstract class MaskedImage
        extends ImageView
{
    private static final Xfermode a = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
    private Bitmap b;
    private Paint c;

    public MaskedImage(Context paramContext)
    {
        super(paramContext);
    }

    public MaskedImage(Context paramContext, AttributeSet paramAttributeSet)
    {
        super(paramContext, paramAttributeSet);
    }

    public MaskedImage(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
    {
        super(paramContext, paramAttributeSet, paramInt);
    }

    public abstract Bitmap a();

    protected void onDraw(Canvas paramCanvas)
    {
        Drawable localDrawable = getDrawable();
        if (localDrawable == null) {
            return;
        }
        try
        {
            if (this.c == null)
            {
                this.c = new Paint();
                this.c.setFilterBitmap(false);
                this.c.setXfermode(a);
            }
            int i = paramCanvas.saveLayer(0.0F, 0.0F, getWidth(), getHeight(), null,Canvas.ALL_SAVE_FLAG);
            localDrawable.setBounds(0, 0, getWidth(), getHeight());
            localDrawable.draw(paramCanvas);
            if ((this.b == null) || (this.b.isRecycled())) {
                this.b = a();
            }
            paramCanvas.drawBitmap(this.b, 0.0F, 0.0F, this.c);
            paramCanvas.restoreToCount(i);
            return;
        }
        catch (Exception e)
        {
            e.printStackTrace();
//            paramCanvas = new Exception("Attempting to draw with recycled bitmap. View ID = ");
//            System.out.println("localStringBuilder==" + paramCanvas);
        }
    }
}

